package edu.tongji.jiaowu.dao.jdbc;

import java.util.List;

import edu.tongji.jiaowu.dao.EvItemDao;
import com.tongji.quickCRUDQ.define.Row;
import com.tongji.quickCRUDQ.model.CommonBean;
import com.tongji.quickCRUDQ.dao.jdbc.BaseDaoJdbc;

public class EvItemDaoJdbc extends BaseDaoJdbc implements EvItemDao {
	String tableName = "T_EV_ITEM";

	String beanName = "evItem";

	public CommonBean createEvItem() {
		CommonBean evItems = this.createBean(tableName, beanName);
		return evItems;
	}

	/*
	 public CommonBean findEvItems(String refid) {
	 CommonBean evItems=this.createEvItem();
	 String sql="select * from T_EV_ITEM where refid=?";
	 List data=this.getCommonDao().select(sql,new String[]{refid});
	 evItems.addData(data);
	 return evItems;
	 }
	 */
	public CommonBean findEvItemById(String id) {
		CommonBean evItems = this.createEvItem();
		String sql = "select * from T_EV_ITEM where id=?";
		List data = this.getCommonDao().select(sql, new String[] { id });
		evItems.addData(data);
		return evItems;
	}

	public CommonBean findAllEvItems() {
		CommonBean evItems = this.createEvItem();
		String sql = "select * from T_EV_ITEM ";
		List data = this.getCommonDao().select(sql, new String[] {});
		evItems.addData(data);
		return evItems;
	}

	public void insertEvItem(CommonBean evItemBean) {
		List data = evItemBean.getData();
		Row row = this.getRow(tableName);
		this.getCommonDao().templateBatchInsert(row, data, this.getIdGenerator());
	}

	public void updateEvItem(CommonBean evItemBean) {
		List data = evItemBean.getData();
		Row row = this.getRow(tableName);
		this.getCommonDao().templateBatchUpdate(row, data);
	}

	public CommonBean findEvItemByClass(String year, String semester, String classCode, String courseType) {
		String sql="select * from  T_EV_ITEM t where exists(select * from T_EV_CLASS where school_year=? and school_semester=? and code=? and course_type=? and id=t.refid) order by code";
		List data=getCommonDao().select(sql, new String[]{year,semester,classCode,courseType});
		CommonBean bean=createBean(tableName, beanName);
		bean.addData(data);
		return bean;
	}
}
